package com.zrwl.poscloud.xo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.entity.CompanyBusinessConfig;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import com.zrwl.poscloud.xo.mapper.CompanyBusinessConfigMapper;
import com.zrwl.poscloud.xo.service.CompanyBusinessConfigService;
import com.zrwl.poscloud.xo.vo.CompanyBusinessConfigVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商户商务配置 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-05-26
 */
@Service
public class CompanyBusinessConfigServiceImpl extends SuperServiceImpl<CompanyBusinessConfigMapper, CompanyBusinessConfig> implements CompanyBusinessConfigService {

    @Autowired
    private CompanyBusinessConfigService companyBusinessConfigService;
    @Resource
    private CompanyBusinessConfigMapper companyBusinessConfigMapper;

    @Override
    public IPage<CompanyBusinessConfigVO> getPageList(CompanyBusinessConfigVO companyBusinessConfigVO) {
        Page<CompanyBusinessConfig> page = new Page<>();
        page.setCurrent(companyBusinessConfigVO.getCurrentPage());
        page.setSize(companyBusinessConfigVO.getPageSize());
        IPage<CompanyBusinessConfigVO> pageList = companyBusinessConfigMapper.getPageList(page, companyBusinessConfigVO);
        List<CompanyBusinessConfigVO> list = pageList.getRecords();
        pageList.setRecords(list);
        return pageList;
    }

    @Override
    public List<CompanyBusinessConfig> getAllList(CompanyBusinessConfigVO companyBusinessConfigVO) {
        QueryWrapper<CompanyBusinessConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<CompanyBusinessConfig> list = companyBusinessConfigService.list(queryWrapper);
        return list;
    }

    @Override
    public String add(CompanyBusinessConfigVO companyBusinessConfigVO) {
        CompanyBusinessConfig entity = new CompanyBusinessConfig();
        BeanUtils.copyProperties(companyBusinessConfigVO, entity, SysConf.STATUS);
        entity.insert();
        companyBusinessConfigVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
    }

    @Override
    public String edit(CompanyBusinessConfigVO companyBusinessConfigVO) {
        CompanyBusinessConfig entity = companyBusinessConfigService.getById(companyBusinessConfigVO.getUid());
        BeanUtils.copyProperties(companyBusinessConfigVO, entity);
        //entity.setUpdateTime//已通过填充实现，后续可删除(new Date());
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }

    @Override
    public String delete(CompanyBusinessConfigVO companyBusinessConfigVO) {
        CompanyBusinessConfig entity = companyBusinessConfigService.getById(companyBusinessConfigVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        //entity.setUpdateTime//已通过填充实现，后续可删除(new Date());
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }

}
